home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1988 December / Ahoy_Magazine_88-12_1988_Double_L.d64 / Floating Point (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  2KB  |  49 lines

  1. 1 rem===================================
  2. 2 rem
  3. 3 rem     floating point converter
  4. 4 rem         rupert report #60
  5. 5 rem
  6. 6 rem===================================
  7. 10 print"[147]floating point converter"
  8. 15 print "========================"
  9. 20 x0=sqr(36)   :rem: x0 must be first variable
  10. 30 sp$="                                       "+chr$(13)
  11. 40 def fnptr(m)=peek(m)+256*peek(m+1)
  12. 60 false=0: true=not false: c64=false
  13. 70 if fre(0)=fre(1) then c64=true
  14. 80 vp=47: if c64 then vp=45   :rem start variables pointer
  15. 90 sv=fnptr(vp) :rem start variables
  16. 100 s1=sv+2: s2=sv+3: s3=sv+4: s4=sv+5: s5=sv+6  :rem storage area for x0
  17. 110 if not c64 then (NULL) 1
  18. 200 rem ========= fp to stored values ==
  19. 210 print "(x to switch modes; q to quit)"
  20. 220 print "enter floating pt. value :"
  21. 225 input x$: if x$="" then 260
  22. 230 if x$="q" then end
  23. 240 if x$="x" then print "[145][145][145]";sp$;sp$;"[145][145][145]": goto 310
  24. 250 x0=val(x$)
  25. 260 v1=peek(s1): v2=peek(s2): v3=peek(s3): v4=peek(s4): v5=peek(s5)
  26. 270 gosub 1010
  27. 280 goto 210
  28. 300 rem ========= stored values to fp ==
  29. 310 print: print "(x to switch modes; q to quit)"
  30. 320 print "enter 5 stored values  (0 to 255) : "
  31. 330 input "first value";x1$: v1=val(x1$)
  32. 340 if x1$="x" then print "[145][145][145]";sp$;sp$;sp$;"[145][145][145][145]": goto 210
  33. 350 if x1$="q" then end
  34. 360 input "2nd value";x2$: v2=val(x2$)
  35. 370 input "3rd value";x3$: v3=val(x3$)
  36. 380 input "4th value";x4$: v4=val(x4$)
  37. 390 input "5th value";x5$: v5=val(x5$)
  38. 400 poke s1,v1: poke s2,v2: poke s3,v3: poke s4,v4: poke s5,v5
  39. 410 gosub 1010
  40. 420 goto 310
  41. 1000 rem ===== conversion & output =====
  42. 1010 print v1; v2; v3; v4; v5
  43. 1020 rem  -- exponent, mantissa, sign --
  44. 1030 ex=v1-128
  45. 1040 mn=(((v5/256+v4)/256+v3)/256 + (128 or v2))/256
  46. 1050 sn=1: if v2 >= 128 then sn=-1
  47. 1060 print ""; sn*mn; "[146]* 2^"; ex; "[146] =  "; x0; "[146]": print
  48. 1070 return
  49.